package com.nondo.rdp.finance.domain;

import com.nondo.rdp.core.domain.attach.Attach;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 活动
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "activity")
public class Activity extends BaseEntity {
    private Long id;    //自增ID
    private Attach mainImg; //封面图片
    private String title;   //标题
    private String body;    //内容
    private String url; //url地址，选填
    private int type; //活动类型，0=默认展示标题和内容，1=打开url地址
    private int valid;  //永久有效,0=普通开始结束时间，1=永久有效
    private Date startTime; //开始时间
    private Date endTime; //结束时间
    private String stringStartTime; // 字符串开始时间
    private String stringEndTime;//字符串结束时间
    private int isExpire; //活动是否过期，0=未过期，1=已过期

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @OneToOne(cascade = CascadeType.ALL)//表示全级联关系
    @JoinColumn(name = "main_img", unique = true)
    public Attach getMainImg() {
        return mainImg;
    }

    public void setMainImg(Attach mainImg) {
        this.mainImg = mainImg;
    }

    @NotNull(message = "标题不能为空")
    @Length(min = 1, max = 32, message = "标题长度不能超过32个字符")
    @Column(name = "title", length = 32)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "body", columnDefinition = "text")
    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column(columnDefinition = "int default 0", nullable = false)
    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Column(columnDefinition = "int default 0", nullable = false)
    public int getValid() {
        return valid;
    }

    public void setValid(int valid) {
        this.valid = valid;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    @Transient
    public String getStringStartTime() {
        return stringStartTime;
    }

    public void setStringStartTime(String stringStartTime) {
        this.stringStartTime = stringStartTime;
    }

    @Transient
    public String getStringEndTime() {
        return stringEndTime;
    }

    public void setStringEndTime(String stringEndTime) {
        this.stringEndTime = stringEndTime;
    }

    @Transient
    public int getIsExpire() {
        return isExpire;
    }

    public void setIsExpire(int isExpire) {
        this.isExpire = isExpire;
    }
}
